<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-student-classes-edit" th:object="${classes}">
            <input id="id" name="id" type="hidden" th:value="*{id}"/>
            <div class="form-group">
                <label class="col-sm-3 control-label">班级名称：</label>
                <div class="col-sm-8">
                    <input id="name" name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">年级：</label>
                <div class="col-sm-8">
                    <input id="grade" name="grade" th:field="*{grade}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">班主任：</label>
                <div class="col-sm-8">
                    <select id="masterTeacher" name="masterTeacherId" class="form-control">
                    	<option selected th:value="*{masterTeacherId}" th:text="*{masterTeacherName}"></option>
                    </select>
                </div>
            </div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs/select/select2.js}"></script>
    <script type="text/javascript">
    	$(function(){
    		var nameEle = $("#name");
            var nameDefaultValue = "[[${classList.name}]]";
            var prefix = ctx + "module/student/classes";
    		$("#form-student-classes-edit").validate({
    			rules: {
                    name: {
                        required: true,
                        remote: {
                            url: prefix + "/checkClassName",
                            type: "post",
                            dataType: "json",
                            data: {
                                className: function () {
                                    return $.trim(nameEle.val());
                                }
                            },
                            dataFilter: function (data, type) {
                                return data == "0" || nameEle.val() == nameDefaultValue;
                            }
                        }
                    }
                },
                messages:{
                    "name": {
                        remote: "当前班级名称以存在!"
                    }
                },
    			submitHandler: function(form) {
                    var serializeAfterValue = $(form).serialize() +
                    "&masterTeacherName=" + $("#masterTeacher option:selected").text();
    				$.operate.save(prefix + "/edit", serializeAfterValue);
    			}
    		});
    		
    		$("#masterTeacher").select2({
				ajax: {
			        type:'GET',
			        url: prefix + "/queryMasterTeacherFormatSelect2",
			        delay: 250,
			        cache: true
			    }
			});
    		
    	});
	</script>
</body>
</html>
